<template>
  <div class="search">
    <f-form ref="form" :action="api.dept" :form-key="this.formItem.deptId">
      <f-form-item label="部门名称" name="deptName" :required="true" :value="formItem.deptName"/>
      <f-form-item label="部门编码" name="deptCode" :required="true" :value="formItem.deptCode"/>
      <f-form-item label="资信天数" type="number" :required="true" name="reputation" dataType="number" :precision="0" :value="formItem.reputation"/>
      <f-form-item label="资信额度" type="number" data-type="number" :required="true" name="reputationAmount" :value="formItem.reputationAmount"/>
      <f-form-item label="部门负责人" ref="saleMan" type="select" name="salemanId" :value="formItem.salemanId" :data="api.saleman.list" valueKey="saleManId" :params="params" label-key="saleManName" v-if="!isAdd"/>
    </f-form>
  </div>
</template>
<script>
  import api from './js/api'

  export default {
    name: 'deptForm',
    props: {},
    data() {
      return {
        refs: this.$refs,
        api: Object.assign(api, this.api),
        isAdd: true,//是否是添加模式
        loaded: false,//是否加载完成
        params: {
          deptId: ''
        },
        formItem: this.getFormItem()
      }
    },
    methods: {
      getFormItem() {
        return {
          deptId: '',
          deptName: '',
          deptCode: '',
          reputation: 120,
          reputationAmount: 1200000
        }
      },
      //表单赋值
      setData(data) {
        this.$refs.form.resetFields()
        this.formItem = this.getFormItem()
        if (data && data.deptId) {
          let params = {
            deptId: data.deptId
          }
          this.params = params
          this.refs['form'].getDetails(params, (data) => {
            this.formItem = data
            this.loaded = true
          })
          this.isAdd = false
        } else {
          this.loaded = true
        }
      },
      //提交表单
      handleSubmit(callback) {
        this.$refs.form.submit({}, callback)
      }
    },
    created() {
    },
    components: {}
  }
</script>

<style scoped lang="less" rel="stylesheet/less">

</style>
